<?php
namespace Modules\Admin\Controllers;

class UserWalletController extends \Phalcon\Mvc\Controller {
  public function updateAmountByUserCodeAction($account) {
    $resUser = $this -> user::getServiceInstance() -> findFirst('user_code = ' . $account);
    if($resUser['code'] != 0) { return $this -> response -> setJsonContent($resUser); }

    $resValidation = $this -> user::getWalletValidationInstance()
    -> addFields()
    -> addAmount()
    -> execute($this -> request -> getPut());
    if($resValidation['code'] != 0) {
      return $this -> response -> setJsonContent($resValidation);
    }

    return $this -> response -> setJsonContent($this -> user::getWalletServiceInstance() -> deposit(
      $resValidation['data']['fields'],
      $resUser['model'] -> user_id,
      $resUser['model'] -> user_id,
      $resValidation['data']['amount'],
      '管理后台'
    ));
  }
}
